﻿#region GNU GPL Version 3 License

/// Copyright 2013 Shailesh Lolam
/// 
/// This file CreateDeployment.cs is part of AzEzAuto.
/// 
/// AzEzAuto is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
/// 
/// AzEzAuto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
/// 
/// You should have received a copy of the GNU General Public License along with AzEzAuto. If not, see http://www.gnu.org/licenses/.
/// 
/// History:
/// ______________________________________________________________
/// Created         04-2013             Shailesh Lolam

#endregion
      
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace AzEzAuto.Entities.Hosted
{
    [XmlRoot(Namespace = "http://schemas.microsoft.com/windowsazure")]
    public class CreateDeployment : ServicesBase
    {
        [XmlElement(Order = 0)]
        public string Name;

        [XmlElement(Order = 1)]
        public string PackageUrl;

        [XmlElement(Order = 2)]
        public string Label;

        [XmlElement(Order = 3)]
        public string Configuration;

        [XmlElement(Order = 4)]
        public bool StartDeployment;

        [XmlElement(Order = 5)]
        public bool TreatWarningsAsError;

        private ExtensionConfiguration _extConfig;
        public ExtensionConfiguration ExtensionConfiguration
        {
            get
            {
                if (_extConfig == null)
                    _extConfig = new ExtensionConfiguration();
                return _extConfig;
            }
        }
        public bool ShouldSerializeExtensionConfiguration { get { return _extConfig != null && (_extConfig.ShouldSerializeAllRoles() || _extConfig.ShouldSerializeNamedRoles()); } }
    }


    public class ExtensionConfiguration
    {
        private List<Extension> _allRoles;

        [XmlArray("AllRoles")]
        [XmlArrayItem("Extension", Type = typeof(Extension))]
        public List<Extension> AllRoles
        {
            get
            {
                if(_allRoles == null)
                    _allRoles = new List<Extension>();
                return _allRoles;
            }
        }
        public bool ShouldSerializeAllRoles() { return _allRoles != null && _allRoles.Count > 0; }

        private List<ExtRole> _namedRoles;

        public List<ExtRole> NamedRoles
        {
            get
            {
                if (_namedRoles == null)
                    _namedRoles = new List<ExtRole>();
                return _namedRoles;
            }
        }
        public bool ShouldSerializeNamedRoles() { return _namedRoles != null && _namedRoles.Count > 0; }
    }

    [XmlRoot("Role")]
    public class ExtRole
    {
        public string RoleName;

        private List<Extension> _extension;

        [XmlArray("Extensions")]
        [XmlArrayItem("Extension", Type = typeof(Extension))]
        public List<Extension> Extensions
        {
            get
            {
                if (_extension == null)
                    _extension = new List<Extension>();
                return _extension;
            }
        }
    }

    public class Extension
    {
        public string Id;
    }

    [XmlRoot(Namespace = "http://schemas.microsoft.com/windowsazure")]
    public class UpgradeDeployment : ServicesBase
    {
        [XmlElement(Order = 0)]
        public Mode Mode;
        [XmlElement(Order = 1)]
        public string PackageUrl;
        [XmlElement(Order = 2)]
        public string Configuration;
        [XmlElement(Order = 3)]
        public string Label;
        [XmlElement(Order = 4)]
        public string RoleToUpgrade;
        [XmlElement(Order = 5)]
        public bool Force;

    }


    [XmlRoot(Namespace = "http://schemas.microsoft.com/windowsazure")]
    public class Swap : ServicesBase
    {
        [XmlElement(Order = 0)]
        public string Production;
        [XmlElement(Order = 1)]
        public string SourceDeployment;

    }

    [XmlRoot(Namespace = "http://schemas.microsoft.com/windowsazure")]
    public class RollbackUpdateOrUpgrade : ServicesBase
    {
        [XmlElement(Order = 0)]
        public Mode Mode;
        [XmlElement(Order = 1)]
        public bool Force;
    }

    [XmlRoot(Namespace = "http://schemas.microsoft.com/windowsazure")]
    public class ChangeConfiguration : ServicesBase
    {
        [XmlElement(Order = 0)]
        public string Configuration;
        [XmlElement(Order = 1)]
        public bool TreatWarningsAsError;
        [XmlElement(Order = 2)]
        public Mode Mode;
    }

    [XmlRoot(Namespace = "http://schemas.microsoft.com/windowsazure")]
    public class WalkUpgradeDomain : ServicesBase
    {
        [XmlElement(Order = 0)]
        public int UpgradeDomain;
    }
}
